package com.kkb.controller;

import com.github.pagehelper.PageHelper;
import com.kkb.base.mapper.ProductsMapper;
import com.kkb.base.pojo.MyProducts;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@RestController
public class ProductsController {
    @Autowired
    private ProductsMapper productsMapper;

    @RequestMapping("/list")
    public List<MyProducts> getProductsList() {
        //List<Products> products = productsMapper.selectAll();
        PageHelper.startPage(0, 2);
        Example example = new Example(MyProducts.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("cid", "s002");
        List<MyProducts> list = productsMapper.selectByExample(example);
        MyProducts myProducts = new MyProducts();
        myProducts.setCid("s002");
        RowBounds rowBounds = new RowBounds(0, 10);
        List<MyProducts> list1 = productsMapper.selectByRowBounds(myProducts, rowBounds);
        return list1;
    }
    @RequestMapping("/price/sum")
    public long getPriceSum() {
        int sumPrice = productsMapper.getSumPrice();
        return sumPrice;
    }
    @RequestMapping("/products/{cid}")
    public List<MyProducts> getProductsByCid(@PathVariable String cid) {
        List<MyProducts> list = productsMapper.getListByCid(cid);
        return list;
    }

}
